package ch06.service.impl;

import ch06.dao.UserDao;
import ch06.entity.User;
import ch06.service.UserService;
import org.springframework.stereotype.Service;

@Service("userService")
public class UserServiceImpl implements UserService {
    //声明接口类型的引用，和具体实现类解耦合
    private UserDao userDao;
    //无参构造

    public UserServiceImpl() {
    }

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }
//通过工厂获取所依赖的USerDao对象
//    private UserDao dao= UserDaoFactory.getInstance();
    /**
     * 声明接口类型的引用，和具体实现类解耦合
     */

    /**
     * 保存用户信息
     * @param user
     */
    public void save(User user){
        //调用UserDao的方法保存用户信息
//        dao.save(user);
        userDao.save(user);
    }

    /**
     * dao属性的setter访问器，会被Spring调用，实现设值注入
     * @param userDao
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
